package com.atguigu.gmall.oms.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

//延时对列
@Configuration
public class RabbitMqConfig {

    //注册进spring容器
    //ttl队列
    @Bean("ORDER-TTL-QUEUE")
    public Queue ttlQueue(){

        Map<String,Object> map=new HashMap<>();
        //使用的都是同一个交换机，只是router-key不一样了
        map.put("x-dead-letter-exchange","GMALL-ORDER-EXCHANGE");
        map.put("x-dead-letter-routing-key","order.dead");
        map.put("x-message-ttl",120000);
        return new Queue("ORDER-TTL-QUEUE",true,false,false,map);
    }
    //绑定
    @Bean("ORDER-TTL-BINDING")
    public Binding ttlBinding(){

        return new Binding("ORDER-TTL-QUEUE", Binding.DestinationType.QUEUE,"GMALL-ORDER-EXCHANGE","order.ttl",null);

    }
    //死性队列
    @Bean("ORDER-DEAD-QUEUE")
    public Queue dlQueue(){
        return new Queue("ORDER-DEAD-QUEUE",true,false,false,null);
    }

    //绑定
    @Bean("ORDER-DEAD-BINDING")
    public Binding deadBinding(){
        return new Binding("ORDER-DEAD-QUEUE", Binding.DestinationType.QUEUE,"GMALL-ORDER-EXCHANGE","order.dead",null);
    }
}
